
package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.TypeFormulaNoteDao;
import com.android.formula.database.NoteDatabaseConnection;
import com.android.formula.model.NoteSubject;
import com.android.formula.model.TypeFormula;
import com.android.formula.utils.Constants;

/**
 * Get a Spot by Id
 */
public class GetTypeFormulaDBTask extends BaseDatabaseTask<NoteSubject, ArrayList<TypeFormula>> {

    public GetTypeFormulaDBTask(Context context, NoteSubject param,
            IDataEventHandler<ArrayList<TypeFormula>> dataEventHandler) {
        super(context, param, null, dataEventHandler);
    }

    @Override
    protected ArrayList<TypeFormula> execute() {
        NoteDatabaseConnection sqlt = MyApplication.getDatabaseConnection();
        if (sqlt == null) {
            return null;
        }

        sqlt.open();
        TypeFormulaNoteDao dao = new TypeFormulaNoteDao(TypeFormula.class, mContext,
                sqlt.getDatabase());
        ArrayList<TypeFormula> list = dao
                .getItemsFromId(Constants.TABLE_TYPE_FORMULA_COL_TYPE_SUBJECTID, ""
                        + mRequestParams.getSubjectId());
        sqlt.close();
        if (!list.isEmpty()) {
            return list;
        } else {
            return null;
        }
    }
}
